package 越长越合法

func numberOfSubstrings1(s string) int {
	diff := map[int32]int{}
	left, cnt := 0, 0
	for right, c := range s {
		diff[c]++
		for len(diff) >= 3 {
			diff[int32(s[left])]--
			if diff[int32(s[left])] == 0 && left <= right {
				delete(diff, int32(s[left]))
			}
			left++
		}
		cnt += left
	}
	return cnt
}
